We back in single salt databehandling
SS=rbind(Data,tst,tst2)
SS$recovery=SS$time/6
Mw_Cl=35.45
Mw_Na=22.99
Mw_Ca=40.078
Mw_SO4=96.06
Mw_SiO2=60.08
SS = SS%>%mutate("f_Na_mmol"=f_Na/Mw_Na)
SS = SS%>%mutate("f_Ca_mmol"=f_Ca/Mw_Ca)
SS = SS%>%mutate("f_Cl_mmol"=f_Cl/Mw_Cl)
SS = SS%>%mutate("f_SiO2_mmol"=f_SiO2/Mw_SiO2)
SS = SS%>%mutate("p_Na_mmol"=p_Na/Mw_Na)
SS = SS%>%mutate("p_Ca_mmol"=p_Ca/Mw_Ca)
SS = SS%>%mutate("p_Cl_mmol"=p_Cl/Mw_Cl)
SS = SS%>%mutate("p_SiO2_mmol"=p_SiO2/Mw_SiO2)
SS_plot=SS%>%gather(key="key",value="value",f_Na_mmol,f_Cl_mmol,f_SiO2_mmol,f_Ca_mmol)
SS_plot$ion=c(rep("Na",21),rep("Cl",21),rep("SiO2",21),rep("Ca",21))
SS_plot$var="Concentration"
ggplot(SS_plot,aes(x=recovery,y=value,color=ion))+geom_point()+geom_line()+facet_grid(cols=vars(exp))
## Warning: Removed 48 rows containing missing values (geom_point).
## Warning: Removed 46 row(s) containing missing values (geom_path).

SS_rej=SS%>%gather(key="key",value="value",Rej_Na,Rej_Cl,Rej_SiO2,Rej_Ca)
SS_rej$ion=c(rep("Na",21),rep("Cl",21),rep("SiO2",21),rep("Ca",21))
SS_rej$var="Rejection [%]"
ggplot(SS_rej,aes(x=recovery,y=value,color=ion))+geom_point()+geom_line()+facet_grid(cols=vars(exp))
## Warning: Removed 54 rows containing missing values (geom_point).
## Warning: Removed 50 row(s) containing missing values (geom_path).

SS_tot_plot=SS%>%gather(key="key",value="value",f_Na_mmol,f_Cl_mmol,f_SiO2_mmol,f_Ca_mmol,Rej_Na,Rej_Cl,Rej_SiO2,Rej_Ca)
SS_tot_plot$ion=rep(c(rep("Na",21),rep("Cl",21),rep("SiO2",21),rep("Ca",21)),2)
SS_tot_plot$var=c(rep("Feed Concentration [mM]",84),rep("Rejection [%]",84))
ggplotly(ggplot(SS_tot_plot,aes(x=recovery,y=value,color=ion))+geom_point()+geom_line()+ylim(0,NA)+
facet_grid(cols=vars(exp),row =vars(var),scale="free",switch=NULL))
ioner=c(expression(Ca^{textstyle("2+")}),expression(Cl^{textstyle("-")}),expression(Na^{textstyle("+")}),expression(SiO[2]),expression(SO[4]^{textstyle("2-")}))
colors2=c(
'#d62728', # brick red
'#1f77b4', # muted blue
'#2ca02c', # cooked asparagus green
'#9467bd', # muted purple
'#ff7f0e', # safety orange
'#8c564b', # chestnut brown
'#e377c2', # raspberry yogurt pink
'#7f7f7f', # middle gray
'#bcbd22', # curry yellow-green
'#17becf' # blue-teal
)
ggplot(SS_tot_plot,aes(x=recovery*100,y=value,color=ion))+geom_point()+geom_line()+ylim(0,NA)+
xlab("Water Recovery [%]")+ylab(" ")+
scale_color_manual(labels = ioner, values =colors2)+labs(colour = "Species")+
theme(legend.text.align=0)+facet_grid(cols=vars(exp),row=vars(var),scale="free")
## Warning: Removed 102 rows containing missing values (geom_point).
## Warning: Removed 46 row(s) containing missing values (geom_path).

#bud på at lave den pæn, no worky
#ggplotly(ggplot(SS_tot_plot,aes(x=recovery,y=value,color=ion))+geom_point()+geom_line()+ylim(0,NA)+
# facet_grid(cols=vars(exp),row =vars(var),scale="free"))+
#scale_color_brewer(palette= "Set1")
#ggplot()+geom_line(data=dat_M_9.2,aes(x=100*(1-(10-sek/60/60*1.02)/10),y=pH0201,color="ID:1 - pH 9.3"))+
# geom_line(data=dat_M_10,aes(x=100*(1-(8.5-sek/60/60*1.02)/8.5),y=pH0201,color="ID:2 - pH 10.1"))+
# geom_line(data=dat_M_10.5,aes(x=100*(1-(10-sek/60/60*1.02)/10),y=pH0201,color="ID:3 - pH 10.5"))+
#+
# scale_x_continuous(limits=c(0, 90), breaks=c(0,20, 40,60,80 ))+
# scale_y_continuous(limits=c(9, 10.75), breaks=c(9,9.5,10,10.5 ))+